package controller;

import po.Info;
import service.impl.InfoImpl;


public class MainController extends BaseController {
	public MainController() {
		viewPath += "main/";
	}
	
	public void index() {
		try {
			InfoImpl ser = new InfoImpl();
			setAttr("fir",ser.getFirOne());
		} catch (Exception e) {
			e.printStackTrace();
		}
		renderJsp("index.jsp");
	}

	public void newinfo(){
		renderJsp("newinfo.jsp");
	}
	public void saveInfo(){
		try {
			Info model = new Info();
			InfoImpl ser = new InfoImpl();
			model.setTerm_num(getParaToLong("term_num"));
			model.setSale(getParaToLong("sale"));
			model.setPrise(getParaToLong("prise"));
			model.setTime(getPara("time"));
			/*
			model.setRed1(getParaToInt("red1"));
			model.setRed2(getParaToInt("red2"));
			model.setRed3(getParaToInt("red3"));
			model.setRed4(getParaToInt("red4"));
			model.setRed5(getParaToInt("red5"));
			model.setRed6(getParaToInt("red6"));
			model.setBlue(getParaToInt("blue"));
			String num_str = getPara("red1")+","+getPara("red2")+","+getPara("red3")+","+getPara("red4")+","
					+getPara("red5")+","+getPara("red6")+","+getPara("blue");*/
			model.setNum_str(getPara("num_str"));
			
			model.setPrise1(getParaToInt("prise1"));
			model.setPrise2(getParaToInt("prise2"));
			model.setPrise3(getParaToInt("prise3"));
			model.setPrise4(getParaToInt("prise4"));
			model.setPrise5(getParaToInt("prise5"));
			model.setPrise6(getParaToInt("prise6"));
			
			model.setPrise1_num(getParaToInt("prise1_num"));
			model.setPrise2_num(getParaToInt("prise2_num"));
			model.setPrise3_num(getParaToInt("prise3_num"));
			model.setPrise4_num(getParaToInt("prise4_num"));
			model.setPrise5_num(getParaToInt("prise5_num"));
			model.setPrise6_num(getParaToInt("prise6_num"));
			long id = ser.saveOrUpdate(model);
			if(id>0){
				getJsonResult().setStatus(1);	
			}else{
				getJsonResult().setStatus(0);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		renderJson(getJsonResult());
	}
}
